/*
 * Copyright (c) 2007 Compl Yue Still, All Rights Reserved.
 */

package hbi.wire.java.host;

import hbi.wire.ProtocolError;

import java.io.IOException;
import java.nio.ByteBuffer;

class BoolElement implements DataTag
{

    private Object value = null;

    public Object getTagValue()
    {
        return value;
    }

    public void reset()
    {
        value = null;
    }

    public boolean processIncomingData(ByteBuffer buffer) throws IOException
    {
        if (buffer.remaining() < 1) return false;
        int tag = buffer.get() & 0xFF;
        switch (tag)
        {
        case 'T':
            value = Boolean.TRUE;
            break;
        case 'F':
            value = Boolean.FALSE;
            break;
        default:
            throw new ProtocolError("Bad boolean value: " + tag);
        }
        return true;
    }

}
